﻿using System;
using System.Collections.Generic;
using WAD.WEB.AppCode;
using System.Text;
using WAD.Model;
using WAD.DAL;

namespace WAD.WEB.Admin.Ajax
{
    /// <summary>
    /// action 的摘要说明
    /// </summary>
    public class action : AdminAjax
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "getlist": this.GetList(); break;
            }
        }
        [QD.Web.Ajax.AjaxMethod]
        public void GetList()
        {
            int pageIndex = Parse.Int("page_index", 1);//当前页
            int pageSize = Parse.Int("pagesize", 20);//当前页
            string fields = Parse.String("fields", "*");
            string table = Parse.String("table", "");
            string order = Parse.String("order", "id desc");
            string fields_Where = Parse.String("fields_where", "");

            if (string.IsNullOrEmpty("table"))
                ParamError();


            StringBuilder sb = new StringBuilder();
            sb.Append("1=1");

            string[] arrKey = { "table", "page_index", "pagesize", "fields", "order", "token", "adminid" };
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (string.IsNullOrEmpty(Request.Form[i]))
                    continue;

                //bool isTrue = true;
                string key = Request.Form.Keys[i].ToLower();
                //for (int j = 0; j < arrKey.Length; j++)
                //{
                //    if (arrKey[j].Equals(key))
                //    {
                //        isTrue = false;
                //        continue;
                //    }
                //}

                //if (isTrue)
                //    sb.AppendFormat(" and {0}='{1}'", key, Request.Form[i]);

                if (fields_Where.IndexOf(key) > -1 && (!string.IsNullOrEmpty(Request.Form[i])))
                    sb.AppendFormat(" and {0}='{1}'", key, Request.Form[i]);
            }

            

            PageData pg = DAOFCRecord.GetListPage(fields, order, pageIndex, pageSize, sb.ToString(), table);
            if (pg.itemCount == 0)
                DataEmpty();
            Success(pg);
        }
    }
}